//
//  BNRItem.m
//  Homepwner
//
//  Created by zhaoxiaoyan on 16/12/26.
//  Copyright © 2016年 xiaoyanzhao. All rights reserved.
//

#import "BNRItem.h"

@implementation BNRItem

- (instancetype)initWithItemName:(NSString *)name valueInDollars:(int)value serialNumber:(NSString *)sNumber {
    self = [super init];
    if (self) {
        _itemName = name;
        _serialNumber = sNumber;
        _valueInDollars = value;
        
        _dateCreate = [[NSDate alloc] init];
    }
    return self;
}

+ (instancetype)randomItem {
    NSArray *randomAdjectiveList = @[@"Fluffy", @"Rusty", @"Shiny"];
    
    NSArray *randomNounList = @[@"Bear", @"Spork", @"Mac"];
    
    NSInteger adjectiveIndex = arc4random() % [randomAdjectiveList count];
    NSInteger nounListIndex = arc4random() %[randomNounList count];
    
    NSString *randomName = [NSString stringWithFormat:@"%@ %@", [randomAdjectiveList objectAtIndex:adjectiveIndex], [randomNounList objectAtIndex:nounListIndex]];
    
    int randomValue = arc4random() % 100;
    NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c", '0' + arc4random() % 10, 'A' + arc4random() % 26, '0' + arc4random() % 10, 'A' + arc4random() % 26, '0' + arc4random() % 10];
    BNRItem *newItem = [[self alloc] initWithItemName:randomName valueInDollars:randomValue serialNumber:randomSerialNumber];
    return newItem;
}

- (instancetype)initWithItemName:(NSString *)name {
    return [self initWithItemName:name valueInDollars:0 serialNumber:@""];
}

- (instancetype)init {
    return [self initWithItemName:@"Item"];
}

//- (void)setItemName:(NSString *)str {
//    _itemName = str;
//}
//
//- (NSString *)itemName {
//    return _itemName;
//}
//
//- (void)setSerialNumber:(NSString *)str {
//    _serialNumber = str;
//}
//
//- (NSString *)serialNumber {
//    return _serialNumber;
//}
//
//- (void)setValueInDollars:(int)v {
//    _valueInDollars = v;
//}
//
//- (int)valueInDollars {
//    return _valueInDollars;
//}
//
//- (NSDate *)dateCreate {
//    return _dateCreate;
//}

- (NSString *)description {
    NSString *descriptionString = [[NSString alloc] initWithFormat:@"%@ (%@): Worth $%d, recorded on %@", self.itemName, self.serialNumber, self.valueInDollars, self.dateCreate];
    return descriptionString;
}

@end
